<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head th:replace="admin/base :: commonHead(_,_)"></head>

<body>
<div class="lyear-layout-web">
    <div class="lyear-layout-container">
        <!--左侧导航-->
        <aside th:replace="admin/base :: commonMenu"></aside>
        <!--End 左侧导航-->

        <!--头部信息-->
        <header th:replace="admin/base :: commonHeader"></header>
        <!--End 头部信息-->

        <!--页面主要内容-->
        <main class="lyear-layout-content">

            <div class="container-fluid">

                <div class="row">
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-toolbar clearfix">
                                <form class="pull-right search-bar" method="get" action="/admin/article/searchArticle"
                                      role="form">
                                    <div class="input-group">
                                        <div class="input-group-btn">
                                            <input type="hidden" name="search_field" id="search-field" value="title">
                                            <button class="btn btn-default dropdown-toggle" id="search-btn"
                                                    data-toggle="dropdown" type="button" aria-haspopup="true"
                                                    aria-expanded="false">
                                                标题 <span class="caret"></span>
                                            </button>
                                            <ul class="dropdown-menu" id="dropdown-menu-lists">
                                                <li><a tabindex="-1" href="javascript:void(0)" data-field="title">标题</a>
                                                </li>
                                                <li><a tabindex="-1" href="javascript:void(0)"
                                                       data-field="content">内容</a></li>
                                            </ul>
                                        </div>
                                        <input type="text" class="form-control" value="" name="keyword"
                                               placeholder="请输入名称">
                                    </div>
                                </form>
                                <div class="toolbar-btn-action">
                                    <a class="btn btn-primary m-r-5" href="/admin/article/add"><i
                                            class="mdi mdi-plus"></i> 新增</a>
                                    <a class="btn btn-success m-r-5" href="#!"><i class="mdi mdi-check"></i> 启用</a>
                                    <a class="btn btn-warning m-r-5" href="#!"><i class="mdi mdi-block-helper"></i>
                                        禁用</a>
                                    <a class="btn btn-danger" href="#!"><i class="mdi mdi-window-close"></i> 删除</a>
                                </div>
                            </div>
                            <div class="card-body">

                                <div class="table-responsive">
                                    <table class="table table-bordered">
                                        <thead>
                                        <tr>
                                            <th>文章编号</th>
                                            <th>标题</th>
                                            <th>作者</th>
                                            <th>阅读量</th>
                                            <th>置顶状态</th>
                                            <th>创建时间</th>
                                            <th>操作</th>
                                        </tr>
                                        </thead>
                                        <tbody th:each="article: ${pageInfo.list}">
                                        <tr>
                                            <td th:text="${article.getId()}">1</td>
                                            <td th:text="${article.getTitle()}">第01章 天涯思君不可忘</td>
                                            <td th:text="${article.author.username}">金庸</td>
                                            <td th:text="${article.getViews()}">36</td>
                                            <td th:text="${article.getTop()}"><font class="text-success">正常</font>
                                            </td>
                                            <td th:text="${#dates.format(article.getCreatedTime(), 'yyyy-MM-dd HH:mm:ss')}">
                                                《倚天屠龙记》
                                            </td>

                                            <td>
                                                <div class="btn-group">
                                                    <a class="btn btn-xs btn-default"
                                                       th:href="'/admin/article/edit/detail/' + ${article.getId()}"
                                                       href="#!" title="编辑"
                                                       data-toggle="tooltip"><i class="mdi mdi-pencil"></i></a>
                                                    <a class="btn btn-xs btn-default"
                                                       th:href="'https://ch3nnn.cn/archives/' + ${article.getId()} + '.html'"
                                                       href="#!" title="查看"
                                                       data-toggle="tooltip"><i class="mdi mdi-eye"></i></a>
                                                    <a th:onclick="clickDeleteArticle([[${article.getId()}]])"
                                                       class="btn btn-xs btn-default" id="delete_archive_click"
                                                       title="删除"
                                                       data-toggle="tooltip"><i class="mdi mdi-window-close"></i></a>
                                                </div>
                                            </td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>

                                <!--显示分页信息-->
                                <div class="modal-footer no-margin-top" th:if="${pageInfo.total != pageInfo.pageSize}">
                                    <div class="col-md-6">
                                        <ul class="pagination">
                                            <li><a th:href="${#request.getRequestURI()} + '?pageNum=1'">«</a></li>
                                            <!--遍历条数-->
                                            <li th:each="nav:${pageInfo.navigatepageNums}"
                                                th:class="${nav == pageInfo.pageNum} ? 'active'">
                                                <a th:href="${#request.getRequestURI()} +'?pageNum='+${nav}"
                                                   th:text="${nav}"
                                                   th:if="${nav != pageInfo.pageNum}"></a>
                                                <a class="active"
                                                   th:href="${#request.getRequestURI()} + '?pageNum='+${nav}"
                                                   th:if="${nav == pageInfo.pageNum}" th:text="${nav}"></a>
                                            </li>
                                            <li>
                                                <a th:href="${#request.getRequestURI()} + '?pageNum='+${pageInfo.pages}">»</a>
                                            </li>

                                        </ul>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                </div>

            </div>

        </main>
        <!--End 页面主要内容-->
        </aside>
    </div>
</div>
<footer th:replace="admin/base :: commonFooter"></footer>
<!--消息通知-->
<script type="text/javascript">

    function clickDeleteArticle(id) {
        lightyear.loading('show');
        // 假设ajax提交操作
        $.ajax({
            type: "DELETE",
            url: "/admin/article/delete/" + id,
            contentType: "application/json",
            dataType: "json",
            timeout: 50000,
            data: JSON.stringify({"articleId": id}),
            async: false,
            success: function (data) {
                lightyear.loading('show');
                // 假设ajax提交操作
                setTimeout(function () {
                    lightyear.loading('hide');
                    lightyear.url(document.URL);  // 先指定跳转链接
                    if (data.code === 1) {
                        lightyear.notify('删除成功，页面即将刷新', 'success', 300);
                    } else {
                        lightyear.notify(data.msg, 'warning', 400);
                    }
                }, 1e3)
            },
            error: function (err) {
                setTimeout(function () {
                    lightyear.loading('hide');
                    lightyear.notify('服务器错误，请稍后再试~', 'danger', 400);
                }, 1e3)
            }
        });
    }
</script>
<!--<script type="text/javascript" th:src="@{/js/bootstrap-notify.min.js}"></script>-->
<!--<script type="text/javascript" th:src="@{/js/lightyear.js}"></script>-->
</body>
</html>